/**
 * 品牌
 * 文件命名格式：zmn.模块名称.表名称.功能.jas
 * @author duanzucai
 * @since 2018/11/10
 */
layui.define(['index', 'form', 'table', 'laypage', 'layedit', 'laydate','jquery'], function (exports) {
    var $ = layui.$;
    var table = layui.table;
    var laypage = layui.laypage;
    var laydate = layui.laydate;
    var form = layui.form;
    zmnLayUtil.layFormVerify(form);
    table.init('zmn-table', {
        toolbar: "#zmn-table-tool",
        page: true,
        limit: json.pageSize,
        height: 'full-140',
        defaultToolbar: []
    });

    laypage.render(layui.$.extend({limits:[10, 20, 30, 40, 50,100]},zmnPage.laypageOptions(json)));

    //查询条件重置
    form.on('submit(zmn-form-reset)', function (obj) {
        form.val("zmn-form-filter", {
            "nameOrTariffId": "" // "name": "value"
            ,"keepType": ""
            ,"tariffType": ''
            ,"status": ""
            ,"priceType": ""
        });
        return false;
    });

    var ids = new Array();

    // 选择（全选或单选）
    table.on("checkbox(zmn-table)", function () {
        ids = table.checkStatus('zmn-table').data.map((item) => item.tariffId);
    });

    // 修改排序
    table.on("edit(zmn-table)", function (obj) {
        if(obj.field=='sort'){
            zmnPage.laySortPositiveInteger(obj.value,"/service/tariff/updateSort.action",obj.data.tariffId,100000,1000)
        }else if(obj.field=='firstLetter'){
            zmnPage.layFirstLetter(obj.value,"/service/tariff/updateFirstLetter.action",obj.data.tariffId,3,1000);
        }
    });

    // 启用/停用
    table.on("toolbar(zmn-table)", function (obj) {
        if (obj.event != "start" && obj.event != "stop") {
            return;
        }
        if (ids.length === 0) {
            return layer.alert("请选择至少一条数据！");
        }
        zmnPage.layStartStop(obj, "/service/tariff/updateStatus.action", ids.join(","));
    });

    //对外暴露的接口
    exports('serv_service_tariff_list', {});
});